/*
 * @(#)UpdateAlertType.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.alert.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import org.apache.commons.dbutils.DbUtils;

import com.dcivision.alert.bean.UpdateAlert;
import com.dcivision.alert.bean.UpdateAlertType;
import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.ErrorConstant;
import com.dcivision.framework.GlobalConstant;
import com.dcivision.framework.SessionContainer;
import com.dcivision.framework.TextUtility;
import com.dcivision.framework.UserInfoFactory;
import com.dcivision.framework.Utility;
import com.dcivision.framework.bean.AbstractBaseObject;
import com.dcivision.framework.dao.AbstractDAObject;
import com.dcivision.framework.web.AbstractSearchForm;
/**
  UpdateAlertTypeDAObject.java
  This class is the data access bean for table "UPDATE_ALERT_TYPE".
  @author      Zoe Shum
  @company     DCIVision Limited
  @creation date   12/02/2004
  @version     $Revision: 1.34.2.1 $
*/
public class UpdateAlertTypeDAObject extends AbstractDAObject {

  public static final String REVISION = "$Revision: 1.34.2.1 $";

  public static final String TABLE_NAME = "UPDATE_ALERT_TYPE";
  public UpdateAlertTypeDAObject(SessionContainer sessionContainer, Connection dbConn) {
    super(sessionContainer, dbConn);
  }
  protected void initDBSetting() {
    this.baseTableName = TABLE_NAME;
    this.vecDBColumn.add("ID");
    this.vecDBColumn.add("UPDATE_ALERT_ID");
    this.vecDBColumn.add("ACTION_TYPE");
    this.vecDBColumn.add("NEED_REPLY");
    this.vecDBColumn.add("NOTIFY_WAY");
    this.vecDBColumn.add("RECUR_EVENT");
    this.vecDBColumn.add("ALERT_TIME_TYPE");
    this.vecDBColumn.add("ALERT_TIME");
    this.vecDBColumn.add("DUE_DATE");
    this.vecDBColumn.add("MESSAGE");
    this.vecDBColumn.add("STATUS");
    this.vecDBColumn.add("RECORD_STATUS");
    this.vecDBColumn.add("UPDATE_COUNT");
    this.vecDBColumn.add("CREATOR_ID");
    this.vecDBColumn.add("CREATE_DATE");
    this.vecDBColumn.add("UPDATER_ID");
    this.vecDBColumn.add("UPDATE_DATE");
    this.vecDBColumn.add("ALERT_SUBJECT");
    this.vecDBColumn.add("NOTIFY_SELF ");
  }
  
  protected synchronized AbstractBaseObject getByID(Integer id) throws ApplicationException {
    return this.getUpdateAlertType(id, GlobalConstant.RECORD_STATUS_ACTIVE);
  }
  
  /**
   * EIP-1174 07/01/08 LEE
   * Add a new method to get 'UpdateAlertType' object.
   * @param id
   * @param recordStatus
   * @return
   * @throws ApplicationException
   */
  public synchronized AbstractBaseObject getUpdateAlertType(Integer id, String recordStatus) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.UPDATE_ALERT_ID, A.ACTION_TYPE, A.NEED_REPLY, A.NOTIFY_WAY, A.RECUR_EVENT, A.ALERT_TIME_TYPE, A.ALERT_TIME, A.DUE_DATE, A.MESSAGE, A.STATUS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE,A.ALERT_SUBJECT, A.NOTIFY_SELF ");
        sqlStat.append("FROM   UPDATE_ALERT_TYPE A ");
        sqlStat.append("WHERE  A.ID = ? ");
        if (!Utility.isEmpty(recordStatus)) {
          sqlStat.append("AND A.RECORD_STATUS = ? ");
        }
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, id);
        if (!Utility.isEmpty(recordStatus)) {
          this.setPrepareStatement(preStat, 2, recordStatus);
        }
        rs = preStat.executeQuery();
        if (rs.next()) {
          UpdateAlertType tmpUpdateAlertType = new UpdateAlertType();
          tmpUpdateAlertType.setID(getResultSetInteger(rs, "ID"));
          tmpUpdateAlertType.setUpdateAlertID(getResultSetInteger(rs, "UPDATE_ALERT_ID"));
          tmpUpdateAlertType.setActionType(getResultSetString(rs, "ACTION_TYPE"));
          tmpUpdateAlertType.setNeedReply(getResultSetString(rs, "NEED_REPLY"));
          tmpUpdateAlertType.setNotifyWay(getResultSetString(rs, "NOTIFY_WAY"));
          tmpUpdateAlertType.setRecurEvent(getResultSetString(rs, "RECUR_EVENT"));
          tmpUpdateAlertType.setAlertTimeType(getResultSetString(rs, "ALERT_TIME_TYPE"));
          tmpUpdateAlertType.setAlertTime(getResultSetInteger(rs, "ALERT_TIME"));
          tmpUpdateAlertType.setDueDate(getResultSetTimestamp(rs, "DUE_DATE"));
          tmpUpdateAlertType.setMessage(getResultSetString(rs, "MESSAGE"));
          tmpUpdateAlertType.setStatus(getResultSetString(rs, "STATUS"));
          tmpUpdateAlertType.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpUpdateAlertType.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpUpdateAlertType.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpUpdateAlertType.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpUpdateAlertType.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));

          tmpUpdateAlertType.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpUpdateAlertType.setCreatorName(UserInfoFactory.getUserFullName(tmpUpdateAlertType.getCreatorID()));
          tmpUpdateAlertType.setUpdaterName(UserInfoFactory.getUserFullName(tmpUpdateAlertType.getUpdaterID()));
          tmpUpdateAlertType.setAlertSubject(getResultSetString(rs, "ALERT_SUBJECT"));
          tmpUpdateAlertType.setNotifySelf(getResultSetString(rs, "NOTIFY_SELF"));          
          return(tmpUpdateAlertType);
        } else {
          throw new ApplicationException(ErrorConstant.DB_RECORD_NOT_FOUND_ERROR);
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  protected synchronized List getList(AbstractSearchForm searchForm) throws ApplicationException {
    PreparedStatement preStat = null;
    PreparedStatement preStatCnt = null;
    ResultSet rs = null;
    ResultSet rsCnt = null;
    StringBuffer sqlStat = new StringBuffer();
    StringBuffer sqlStatCnt = new StringBuffer();
    List result = new ArrayList();
    int totalNumOfRecord = 0;
    int rowLoopCnt = 0;
    int startOffset = TextUtility.parseInteger(searchForm.getCurStartRowNo());
    int pageSize = TextUtility.parseInteger(searchForm.getPageOffset());
    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.UPDATE_ALERT_ID, A.ACTION_TYPE, A.NEED_REPLY, A.NOTIFY_WAY, A.RECUR_EVENT, A.ALERT_TIME_TYPE, A.ALERT_TIME, A.DUE_DATE, A.MESSAGE, A.STATUS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE,A.ALERT_SUBJECT, A.NOTIFY_SELF ");
        sqlStat.append("FROM   UPDATE_ALERT_TYPE A ");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? ");
        // Form the WHERE clause for filtering.
        /*
        if (searchForm.isSearchable()) {
          String searchField = getSearchColumn(searchForm.getBasicSearchField());
          sqlStat.append("AND  " + searchField + " " + searchForm.getBasicSearchType() + " ? ");
        }*/
        
        if (searchForm.isSearchable()) {
          String searchField = getSearchColumn(searchForm.getBasicSearchField());
          sqlStat.append("AND  " + searchField + " " + searchForm.getBasicSearchType() + " ? ");
        }
        
        //format the sql for any 'LIKE' statement contained
        sqlStat = this.getFormattedSQL(sqlStat.toString());
        // Form the ORDER clause for sorting.
        if (searchForm.isSortable()) {
          String sortAttribute = searchForm.getSortAttribute();
          if (sortAttribute.indexOf(".") < 0) {
            sortAttribute = "A." + sortAttribute;
          }
          sqlStat.append("ORDER BY " + sortAttribute + " " + searchForm.getSortOrder());
        }
        // Get total number of record return.
        sqlStatCnt = this.getSelectCountSQL(sqlStat);
        preStatCnt = dbConn.prepareStatement(sqlStatCnt.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStatCnt, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        if (searchForm.isSearchable()) {
          String searchKeyword = this.getFormattedKeyword(searchForm.getBasicSearchKeyword(), searchForm.getBasicSearchType());
          this.setPrepareStatement(preStatCnt, 2, searchKeyword);
        }
        rsCnt = preStatCnt.executeQuery();
        if (rsCnt.next()) {
          totalNumOfRecord = rsCnt.getInt(1);
        }
        try { rsCnt.close(); } catch (Exception ignore) {} finally { rsCnt = null; }
        try { preStatCnt.close(); } catch (Exception ignore) {} finally { preStatCnt = null; }
        // Retrieve the result in row basis.
        sqlStat = this.getSelectListSQL(sqlStat, startOffset, pageSize);
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        if (searchForm.isSearchable()) {
          String searchKeyword = this.getFormattedKeyword(searchForm.getBasicSearchKeyword(), searchForm.getBasicSearchType());
          this.setPrepareStatement(preStat, 2, searchKeyword);
        }
        rs = preStat.executeQuery();
        this.positionCursor(rs, startOffset, pageSize);
        while (rs.next() && rowLoopCnt<pageSize) {
          UpdateAlertType tmpUpdateAlertType = new UpdateAlertType();
          tmpUpdateAlertType.setID(getResultSetInteger(rs, "ID"));
          tmpUpdateAlertType.setUpdateAlertID(getResultSetInteger(rs, "UPDATE_ALERT_ID"));
          tmpUpdateAlertType.setActionType(getResultSetString(rs, "ACTION_TYPE"));
          tmpUpdateAlertType.setNeedReply(getResultSetString(rs, "NEED_REPLY"));
          tmpUpdateAlertType.setNotifyWay(getResultSetString(rs, "NOTIFY_WAY"));
          tmpUpdateAlertType.setRecurEvent(getResultSetString(rs, "RECUR_EVENT"));
          tmpUpdateAlertType.setAlertTimeType(getResultSetString(rs, "ALERT_TIME_TYPE"));
          tmpUpdateAlertType.setAlertTime(getResultSetInteger(rs, "ALERT_TIME"));
          tmpUpdateAlertType.setDueDate(getResultSetTimestamp(rs, "DUE_DATE"));
          tmpUpdateAlertType.setMessage(getResultSetString(rs, "MESSAGE"));
          tmpUpdateAlertType.setStatus(getResultSetString(rs, "STATUS"));
          tmpUpdateAlertType.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpUpdateAlertType.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpUpdateAlertType.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpUpdateAlertType.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpUpdateAlertType.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpUpdateAlertType.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpUpdateAlertType.setCreatorName(UserInfoFactory.getUserFullName(tmpUpdateAlertType.getCreatorID()));
          tmpUpdateAlertType.setUpdaterName(UserInfoFactory.getUserFullName(tmpUpdateAlertType.getUpdaterID()));
          tmpUpdateAlertType.setAlertSubject(getResultSetString(rs, "ALERT_SUBJECT"));
          tmpUpdateAlertType.setNotifySelf(getResultSetString(rs, "NOTIFY_SELF"));
          tmpUpdateAlertType.setRecordCount(totalNumOfRecord);
          tmpUpdateAlertType.setRowNum(startOffset++);
          ++rowLoopCnt;
          result.add(tmpUpdateAlertType);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
        try { rsCnt.close(); } catch (Exception ignore) {} finally { rsCnt = null; }
        try { preStatCnt.close(); } catch (Exception ignore) {} finally { preStatCnt = null; }
      }
    }
  }
  protected synchronized List getList() throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List result = new ArrayList();
    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.UPDATE_ALERT_ID, A.ACTION_TYPE, A.NEED_REPLY, A.NOTIFY_WAY, A.RECUR_EVENT, A.ALERT_TIME_TYPE, A.ALERT_TIME, A.DUE_DATE, A.MESSAGE, A.STATUS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE,A.ALERT_SUBJECT, A.NOTIFY_SELF  ");
        sqlStat.append("FROM   UPDATE_ALERT_TYPE A ");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        rs = preStat.executeQuery();
        while (rs.next()) {
          UpdateAlertType tmpUpdateAlertType = new UpdateAlertType();
          tmpUpdateAlertType.setID(getResultSetInteger(rs, "ID"));
          tmpUpdateAlertType.setUpdateAlertID(getResultSetInteger(rs, "UPDATE_ALERT_ID"));
          tmpUpdateAlertType.setActionType(getResultSetString(rs, "ACTION_TYPE"));
          tmpUpdateAlertType.setNeedReply(getResultSetString(rs, "NEED_REPLY"));
          tmpUpdateAlertType.setNotifyWay(getResultSetString(rs, "NOTIFY_WAY"));
          tmpUpdateAlertType.setRecurEvent(getResultSetString(rs, "RECUR_EVENT"));
          tmpUpdateAlertType.setAlertTimeType(getResultSetString(rs, "ALERT_TIME_TYPE"));
          tmpUpdateAlertType.setAlertTime(getResultSetInteger(rs, "ALERT_TIME"));
          tmpUpdateAlertType.setDueDate(getResultSetTimestamp(rs, "DUE_DATE"));
          tmpUpdateAlertType.setMessage(getResultSetString(rs, "MESSAGE"));
          tmpUpdateAlertType.setStatus(getResultSetString(rs, "STATUS"));
          tmpUpdateAlertType.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpUpdateAlertType.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpUpdateAlertType.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpUpdateAlertType.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpUpdateAlertType.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpUpdateAlertType.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpUpdateAlertType.setCreatorName(UserInfoFactory.getUserFullName(tmpUpdateAlertType.getCreatorID()));
          tmpUpdateAlertType.setUpdaterName(UserInfoFactory.getUserFullName(tmpUpdateAlertType.getUpdaterID()));
          tmpUpdateAlertType.setAlertSubject(getResultSetString(rs, "ALERT_SUBJECT"));
          tmpUpdateAlertType.setNotifySelf(getResultSetString(rs, "NOTIFY_SELF"));          
          result.add(tmpUpdateAlertType);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  protected void validateInsert(AbstractBaseObject obj) throws ApplicationException {
  }
  protected void validateUpdate(AbstractBaseObject obj) throws ApplicationException {
  }
  protected void validateDelete(AbstractBaseObject obj) throws ApplicationException {
  }
  protected synchronized AbstractBaseObject insert(AbstractBaseObject obj) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    UpdateAlertType tmpUpdateAlertType = (UpdateAlertType)((UpdateAlertType)obj).clone();
    Integer creatorID=sessionContainer.getUserRecordID();
    Integer updaterID=sessionContainer.getUserRecordID();
    if(!Utility.isEmpty(tmpUpdateAlertType.getCreatorID())){
      creatorID=tmpUpdateAlertType.getCreatorID();
    }
    if(!Utility.isEmpty(tmpUpdateAlertType.getUpdaterID())){ 
      updaterID=tmpUpdateAlertType.getUpdaterID();
    }
    synchronized(dbConn) {
      try {
        Integer nextID = getNextPrimaryID();
        Timestamp currTime = Utility.getCurrentTimestamp();
        sqlStat.append("INSERT ");
        sqlStat.append("INTO   UPDATE_ALERT_TYPE(ID, UPDATE_ALERT_ID, ACTION_TYPE, NEED_REPLY, NOTIFY_WAY, RECUR_EVENT, ALERT_TIME_TYPE, ALERT_TIME, DUE_DATE, MESSAGE, STATUS, RECORD_STATUS, UPDATE_COUNT, CREATOR_ID, CREATE_DATE, UPDATER_ID, UPDATE_DATE,ALERT_SUBJECT,NOTIFY_SELF) ");
        sqlStat.append("VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        setPrepareStatement(preStat, 1, nextID);
        setPrepareStatement(preStat, 2, tmpUpdateAlertType.getUpdateAlertID());
        setPrepareStatement(preStat, 3, tmpUpdateAlertType.getActionType());
        setPrepareStatement(preStat, 4, tmpUpdateAlertType.getNeedReply());
        setPrepareStatement(preStat, 5, tmpUpdateAlertType.getNotifyWay());
        setPrepareStatement(preStat, 6, tmpUpdateAlertType.getRecurEvent());
        setPrepareStatement(preStat, 7, tmpUpdateAlertType.getAlertTimeType());
        setPrepareStatement(preStat, 8, tmpUpdateAlertType.getAlertTime());
        setPrepareStatement(preStat, 9, tmpUpdateAlertType.getDueDate());
        setPrepareStatement(preStat, 10, tmpUpdateAlertType.getMessage());
        setPrepareStatement(preStat, 11, tmpUpdateAlertType.getStatus());
        setPrepareStatement(preStat, 12, GlobalConstant.RECORD_STATUS_ACTIVE);
        setPrepareStatement(preStat, 13, new Integer(0));
        setPrepareStatement(preStat, 14, creatorID);
        setPrepareStatement(preStat, 15, currTime);
        setPrepareStatement(preStat, 16, updaterID);
        setPrepareStatement(preStat, 17, currTime);
        setPrepareStatement(preStat, 18, tmpUpdateAlertType.getAlertSubject());
        setPrepareStatement(preStat, 19, tmpUpdateAlertType.getNotifySelf());        
        preStat.executeUpdate();
        tmpUpdateAlertType.setID(nextID);
        tmpUpdateAlertType.setCreatorID(creatorID);
        tmpUpdateAlertType.setCreateDate(currTime);
        tmpUpdateAlertType.setUpdaterID(updaterID);
        tmpUpdateAlertType.setUpdateDate(currTime);
        tmpUpdateAlertType.setUpdateCount(new Integer(0));
        tmpUpdateAlertType.setCreatorName(UserInfoFactory.getUserFullName(tmpUpdateAlertType.getCreatorID()));
        tmpUpdateAlertType.setUpdaterName(UserInfoFactory.getUserFullName(tmpUpdateAlertType.getUpdaterID())); 
        return(tmpUpdateAlertType);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_INSERT_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  protected synchronized AbstractBaseObject update(AbstractBaseObject obj) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    UpdateAlertType tmpUpdateAlertType = (UpdateAlertType)((UpdateAlertType)obj).clone();
    synchronized(dbConn) {
      try {
        int updateCnt = 0;
        Timestamp currTime = Utility.getCurrentTimestamp();
        sqlStat.append("UPDATE UPDATE_ALERT_TYPE ");
        sqlStat.append("SET  UPDATE_ALERT_ID=?, ACTION_TYPE=?, NEED_REPLY=?, NOTIFY_WAY=?, RECUR_EVENT=?, ALERT_TIME_TYPE=?, ALERT_TIME=?, DUE_DATE=?, MESSAGE=?, STATUS=?, UPDATE_COUNT=?, UPDATER_ID=?, UPDATE_DATE=? ,ALERT_SUBJECT=?,NOTIFY_SELF=? ");
        sqlStat.append("WHERE  ID=? AND UPDATE_COUNT=? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        setPrepareStatement(preStat, 1, tmpUpdateAlertType.getUpdateAlertID());
        setPrepareStatement(preStat, 2, tmpUpdateAlertType.getActionType());
        setPrepareStatement(preStat, 3, tmpUpdateAlertType.getNeedReply());
        setPrepareStatement(preStat, 4, tmpUpdateAlertType.getNotifyWay());
        setPrepareStatement(preStat, 5, tmpUpdateAlertType.getRecurEvent());
        setPrepareStatement(preStat, 6, tmpUpdateAlertType.getAlertTimeType());
        setPrepareStatement(preStat, 7, tmpUpdateAlertType.getAlertTime());
        setPrepareStatement(preStat, 8, tmpUpdateAlertType.getDueDate());
        setPrepareStatement(preStat, 9, tmpUpdateAlertType.getMessage());
        setPrepareStatement(preStat, 10, tmpUpdateAlertType.getStatus());
        setPrepareStatement(preStat, 11, new Integer(tmpUpdateAlertType.getUpdateCount().intValue() + 1));
        setPrepareStatement(preStat, 12, sessionContainer.getUserRecordID());
        setPrepareStatement(preStat, 13, currTime);
        setPrepareStatement(preStat, 14, tmpUpdateAlertType.getAlertSubject());        
        setPrepareStatement(preStat, 15, tmpUpdateAlertType.getNotifySelf());        
        setPrepareStatement(preStat, 16, tmpUpdateAlertType.getID());
        setPrepareStatement(preStat, 17, tmpUpdateAlertType.getUpdateCount());

        updateCnt = preStat.executeUpdate();
        if (updateCnt == 0) {
          throw new ApplicationException(ErrorConstant.DB_CONCURRENT_ERROR);
        } else {
          tmpUpdateAlertType.setUpdaterID(sessionContainer.getUserRecordID());
          tmpUpdateAlertType.setUpdateDate(currTime);
          tmpUpdateAlertType.setUpdateCount(new Integer(tmpUpdateAlertType.getUpdateCount().intValue() + 1));
          tmpUpdateAlertType.setCreatorName(UserInfoFactory.getUserFullName(tmpUpdateAlertType.getCreatorID()));
          tmpUpdateAlertType.setUpdaterName(UserInfoFactory.getUserFullName(tmpUpdateAlertType.getUpdaterID()));
          return(tmpUpdateAlertType);
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_UPDATE_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  
  protected synchronized AbstractBaseObject delete(AbstractBaseObject obj) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    UpdateAlertType tmpUpdateAlertType = (UpdateAlertType)((UpdateAlertType)obj).clone();
    synchronized(dbConn) {
      try {
        int updateCnt = 0;
        sqlStat.append("DELETE ");
        sqlStat.append("FROM   UPDATE_ALERT_TYPE ");
        sqlStat.append("WHERE  ID=? AND UPDATE_COUNT=? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        setPrepareStatement(preStat, 1, tmpUpdateAlertType.getID());
        setPrepareStatement(preStat, 2, tmpUpdateAlertType.getUpdateCount());
        updateCnt = preStat.executeUpdate();
        if (updateCnt == 0) {
          throw new ApplicationException(ErrorConstant.DB_CONCURRENT_ERROR);
        } else {
          return(tmpUpdateAlertType);
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_DELETE_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  
  protected synchronized void auditTrail(String opMode, AbstractBaseObject obj) throws ApplicationException {
    Vector oldValues = new Vector();
    Vector newValues = new Vector();
    UpdateAlertType tmpUpdateAlertType = (UpdateAlertType)this.oldValue;
    if (tmpUpdateAlertType != null) {
      oldValues.add(toAuditTrailValue(tmpUpdateAlertType.getID()));
      oldValues.add(toAuditTrailValue(tmpUpdateAlertType.getUpdateAlertID()));
      oldValues.add(toAuditTrailValue(tmpUpdateAlertType.getActionType()));
      oldValues.add(toAuditTrailValue(tmpUpdateAlertType.getNeedReply()));
      oldValues.add(toAuditTrailValue(tmpUpdateAlertType.getNotifyWay()));
      oldValues.add(toAuditTrailValue(tmpUpdateAlertType.getRecurEvent()));
      oldValues.add(toAuditTrailValue(tmpUpdateAlertType.getAlertTimeType()));
      oldValues.add(toAuditTrailValue(tmpUpdateAlertType.getAlertTime()));
      oldValues.add(toAuditTrailValue(tmpUpdateAlertType.getDueDate()));
      oldValues.add(toAuditTrailValue(tmpUpdateAlertType.getMessage()));
      oldValues.add(toAuditTrailValue(tmpUpdateAlertType.getStatus()));
      oldValues.add(toAuditTrailValue(tmpUpdateAlertType.getRecordStatus()));
      oldValues.add(toAuditTrailValue(tmpUpdateAlertType.getUpdateCount()));
      oldValues.add(toAuditTrailValue(tmpUpdateAlertType.getCreatorID()));
      oldValues.add(toAuditTrailValue(tmpUpdateAlertType.getCreateDate()));
      oldValues.add(toAuditTrailValue(tmpUpdateAlertType.getUpdaterID()));
      oldValues.add(toAuditTrailValue(tmpUpdateAlertType.getUpdateDate()));
      oldValues.add(toAuditTrailValue(tmpUpdateAlertType.getAlertSubject()));
      oldValues.add(toAuditTrailValue(tmpUpdateAlertType.getNotifySelf()));
    }
    tmpUpdateAlertType = (UpdateAlertType)obj;
    if (tmpUpdateAlertType != null) {
      newValues.add(toAuditTrailValue(tmpUpdateAlertType.getID()));
      newValues.add(toAuditTrailValue(tmpUpdateAlertType.getUpdateAlertID()));
      newValues.add(toAuditTrailValue(tmpUpdateAlertType.getActionType()));
      newValues.add(toAuditTrailValue(tmpUpdateAlertType.getNeedReply()));
      newValues.add(toAuditTrailValue(tmpUpdateAlertType.getNotifyWay()));
      newValues.add(toAuditTrailValue(tmpUpdateAlertType.getRecurEvent()));
      newValues.add(toAuditTrailValue(tmpUpdateAlertType.getAlertTimeType()));
      newValues.add(toAuditTrailValue(tmpUpdateAlertType.getAlertTime()));
      newValues.add(toAuditTrailValue(tmpUpdateAlertType.getDueDate()));
      newValues.add(toAuditTrailValue(tmpUpdateAlertType.getMessage()));
      newValues.add(toAuditTrailValue(tmpUpdateAlertType.getStatus()));
      newValues.add(toAuditTrailValue(tmpUpdateAlertType.getRecordStatus()));
      newValues.add(toAuditTrailValue(tmpUpdateAlertType.getUpdateCount()));
      newValues.add(toAuditTrailValue(tmpUpdateAlertType.getCreatorID()));
      newValues.add(toAuditTrailValue(tmpUpdateAlertType.getCreateDate()));
      newValues.add(toAuditTrailValue(tmpUpdateAlertType.getUpdaterID()));
      newValues.add(toAuditTrailValue(tmpUpdateAlertType.getUpdateDate()));
      newValues.add(toAuditTrailValue(tmpUpdateAlertType.getAlertSubject()));
      newValues.add(toAuditTrailValue(tmpUpdateAlertType.getNotifySelf()));
    }
    auditTrailBase(opMode, oldValues, newValues);
  }
  /***********************************************************************
   * DON'T Modify the codes above unless you know what you are doing!!!  *
   * Put your own functions beblow.                                      *
   * For FINDER methods, the function name should be in the notation:    *
   *   public Object getObjectBy<Criteria>()                             *
   *   - e.g. public Object getObjectByCode()                            *
   *   public List getListBy<Criteria>()                                 *
   *   - e.g. public List getListByUserID()                              *
   * For OPERATION methods, the function name should be in the notation: *
   *   public void <Operation>ObjectBy<Criteria>()                       *
   *   - e.g. public void deleteObjectByCode()                           *
   *   public void <Operation>ListBy<Criteria>()                         *
   *   - e.g. public void deleteListByUserID()                           *
   ***********************************************************************/

  public synchronized void deleteByUpdateAlertID(Integer updateAlertID, String actionType) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();

    synchronized (dbConn) {
      try {
        sqlStat.append("DELETE ");
        sqlStat.append("FROM   UPDATE_ALERT_TYPE ");
        sqlStat.append("WHERE  UPDATE_ALERT_ID=? ");
        if (actionType != null)
          sqlStat.append("AND  ACTION_TYPE = ? ");
        else
          sqlStat.append("AND  ACTION_TYPE <> 'I' ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        //log.debug(sqlStat.toString());
        setPrepareStatement(preStat, 1, updateAlertID);
        if (actionType != null)
          this.setPrepareStatement(preStat, 2, actionType);
        preStat.executeUpdate();

      }
      catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  public synchronized List getByUpdateAlertIDByOwnerID(Integer updateAlertID, Integer curUserID) throws ApplicationException {
    return this.getByUpdateAlertIDByOwnerID(updateAlertID, null, curUserID);
  }



  public synchronized List getByUpdateAlertIDByOwnerID(Integer updateAlertID, String actionType, Integer curUserID) throws
      ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List resultList = new ArrayList();

    synchronized (dbConn) {
      try {
        sqlStat.append("SELECT DISTINCT(A.ID), A.UPDATE_ALERT_ID, A.ACTION_TYPE, A.NEED_REPLY, A.NOTIFY_WAY, A.RECUR_EVENT, A.ALERT_TIME_TYPE, A.ALERT_TIME, A.DUE_DATE, A.MESSAGE, A.STATUS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE, A.ALERT_SUBJECT ,A.NOTIFY_SELF  ");
        sqlStat.append("FROM   UPDATE_ALERT_TYPE A ");
        sqlStat.append("WHERE  (A.UPDATE_ALERT_ID = ?) AND (A.RECORD_STATUS=?) ");
        if (curUserID!=null){
          sqlStat.append("AND  A.CREATOR_ID = ? ");
        }
        if ( (actionType != null) && (! ("ALL".equals(actionType))))
          sqlStat.append("AND  (A.ACTION_TYPE = ?) ");
        else if (actionType == null)
          sqlStat.append("AND  (A.ACTION_TYPE <> 'I') ");
        
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, updateAlertID);
        this.setPrepareStatement(preStat, 2, GlobalConstant.STATUS_ACTIVE);
        int i=3;
        if (curUserID!=null){
          this.setPrepareStatement(preStat, i++, curUserID);
        }
        if ( (actionType != null) && (! ("ALL".equals(actionType))))
          this.setPrepareStatement(preStat, i++, actionType);
        rs = preStat.executeQuery();
        while (rs.next()) {
          UpdateAlertType tmpUpdateAlertType = new UpdateAlertType();
          tmpUpdateAlertType.setID(getResultSetInteger(rs, "ID"));
          tmpUpdateAlertType.setUpdateAlertID(getResultSetInteger(rs, "UPDATE_ALERT_ID"));
          tmpUpdateAlertType.setActionType(getResultSetString(rs, "ACTION_TYPE"));
          tmpUpdateAlertType.setNeedReply(getResultSetString(rs, "NEED_REPLY"));
          tmpUpdateAlertType.setNotifyWay(getResultSetString(rs, "NOTIFY_WAY"));
          tmpUpdateAlertType.setRecurEvent(getResultSetString(rs, "RECUR_EVENT"));
          tmpUpdateAlertType.setAlertTimeType(getResultSetString(rs, "ALERT_TIME_TYPE"));
          tmpUpdateAlertType.setAlertTime(getResultSetInteger(rs, "ALERT_TIME"));
          tmpUpdateAlertType.setDueDate(getResultSetTimestamp(rs, "DUE_DATE"));
          tmpUpdateAlertType.setMessage(getResultSetString(rs, "MESSAGE"));
          tmpUpdateAlertType.setStatus(getResultSetString(rs, "STATUS"));
          tmpUpdateAlertType.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpUpdateAlertType.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpUpdateAlertType.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpUpdateAlertType.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpUpdateAlertType.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpUpdateAlertType.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpUpdateAlertType.setAlertSubject(getResultSetString(rs, "ALERT_SUBJECT"));
          tmpUpdateAlertType.setNotifySelf(getResultSetString(rs, "NOTIFY_SELF"));
          tmpUpdateAlertType.setCreatorName(UserInfoFactory.getUserFullName(tmpUpdateAlertType.getCreatorID()));
          tmpUpdateAlertType.setUpdaterName(UserInfoFactory.getUserFullName(tmpUpdateAlertType.getUpdaterID()));
          resultList.add(tmpUpdateAlertType);
        }
      }
      catch (ApplicationException appEx) {
        throw appEx;
      }
      catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      }
      catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
    return resultList;
  }
  
  public synchronized List getInactiveByUpdateAlertIDByOwnerID(Integer updateAlertID, String actionType, Integer curUserID) throws
				    ApplicationException {
    
    PreparedStatement preStat = null;
	    ResultSet rs = null;
	    StringBuffer sqlStat = new StringBuffer();
	    List resultList = new ArrayList();

	    synchronized (dbConn) {
	    try {
	      sqlStat.append("SELECT DISTINCT(A.ID), A.UPDATE_ALERT_ID, A.ACTION_TYPE, A.NEED_REPLY, A.NOTIFY_WAY, A.RECUR_EVENT, A.ALERT_TIME_TYPE, A.ALERT_TIME, A.DUE_DATE, A.MESSAGE, A.STATUS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
		      sqlStat.append("FROM   UPDATE_ALERT_TYPE A ");
		      sqlStat.append("WHERE  (A.UPDATE_ALERT_ID = ?) AND (A.RECORD_STATUS=?) ");
		      if (curUserID!=null){
	        sqlStat.append("AND  A.CREATOR_ID = ? ");
		      }
		      if ( (actionType != null) && (! ("ALL".equals(actionType))))
		        sqlStat.append("AND  (A.ACTION_TYPE = ?) ");
		      else if (actionType == null)
		        sqlStat.append("AND  (A.ACTION_TYPE <> 'I') ");
		       
      preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
		      this.setPrepareStatement(preStat, 1, updateAlertID);
		      this.setPrepareStatement(preStat, 2, GlobalConstant.STATUS_INACTIVE);
		      int i=3;
		      if (curUserID!=null){
		        this.setPrepareStatement(preStat, i++, curUserID);
		      }
		      if ( (actionType != null) && (! ("ALL".equals(actionType))))
		        this.setPrepareStatement(preStat, i++, actionType);
		  
      rs = preStat.executeQuery();
		      while (rs.next()) {
		        UpdateAlertType tmpUpdateAlertType = new UpdateAlertType();
			        tmpUpdateAlertType.setID(getResultSetInteger(rs, "ID"));
			        tmpUpdateAlertType.setUpdateAlertID(getResultSetInteger(rs, "UPDATE_ALERT_ID"));
		        	tmpUpdateAlertType.setActionType(getResultSetString(rs, "ACTION_TYPE"));
			        tmpUpdateAlertType.setNeedReply(getResultSetString(rs, "NEED_REPLY"));
			        tmpUpdateAlertType.setNotifyWay(getResultSetString(rs, "NOTIFY_WAY"));
			        tmpUpdateAlertType.setRecurEvent(getResultSetString(rs, "RECUR_EVENT"));
			        tmpUpdateAlertType.setAlertTimeType(getResultSetString(rs, "ALERT_TIME_TYPE"));
			        tmpUpdateAlertType.setAlertTime(getResultSetInteger(rs, "ALERT_TIME"));
			        tmpUpdateAlertType.setDueDate(getResultSetTimestamp(rs, "DUE_DATE"));
			        tmpUpdateAlertType.setMessage(getResultSetString(rs, "MESSAGE"));
			        tmpUpdateAlertType.setStatus(getResultSetString(rs, "STATUS"));
		        	tmpUpdateAlertType.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
			        tmpUpdateAlertType.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
			        tmpUpdateAlertType.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
			        tmpUpdateAlertType.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
			        tmpUpdateAlertType.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
			        tmpUpdateAlertType.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
			        tmpUpdateAlertType.setCreatorName(UserInfoFactory.getUserFullName(tmpUpdateAlertType.getCreatorID()));
			        tmpUpdateAlertType.setUpdaterName(UserInfoFactory.getUserFullName(tmpUpdateAlertType.getUpdaterID()));
			        resultList.add(tmpUpdateAlertType);
		      }
		   }catch (ApplicationException appEx) {
	    throw appEx;
	   }catch (SQLException sqle) {
	    log.error(sqle, sqle);
		    throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
	   }catch (Exception e) {
	    log.error(e, e);
		    throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
	   } finally {
	     try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
		     try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
	   }
  }

   	return resultList;
  }
  /**
   * 
   * @param updateAlertID
   * @param actionType
   * @param sortAttribute 
   * @param sortOrder
   * @param curUserID
   * @return
   * @throws ApplicationException
   */
public synchronized List getDocumentInvitationByUpdateAlertID(Integer updateAlertID, String actionType, 
    String sortAttribute, String sortOrder) throws  ApplicationException {

    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List resultList = new ArrayList();

    synchronized (dbConn) {
      try {
        sqlStat
            .append("SELECT DISTINCT(A.ID), A.UPDATE_ALERT_ID, A.ALERT_SUBJECT, A.ACTION_TYPE, A.NEED_REPLY, A.NOTIFY_WAY, A.RECUR_EVENT, A.ALERT_TIME_TYPE, A.ALERT_TIME, A.DUE_DATE, A.MESSAGE, A.STATUS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   UPDATE_ALERT_TYPE A ");
        sqlStat.append("WHERE  (A.UPDATE_ALERT_ID = ?) AND (A.RECORD_STATUS=?) ");

        if (actionType != null) {
          sqlStat.append("AND  (A.ACTION_TYPE = ?) ");
        }
        else if (actionType == null) {
          sqlStat.append("AND  (A.ACTION_TYPE = 'I') ");
        }
        if (sortAttribute.indexOf(".") < 0) {
          sortAttribute = "A." + sortAttribute;
        }
        sqlStat.append("ORDER BY " + sortAttribute + " " + sortOrder);
        preStat = dbConn.prepareStatement(sqlStat.toString(),ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, updateAlertID);
        this.setPrepareStatement(preStat, 2, GlobalConstant.STATUS_ACTIVE);
        if (actionType != null) {
          this.setPrepareStatement(preStat, 3, actionType);
        }

        rs = preStat.executeQuery();
        while (rs.next()) {
          UpdateAlertType tmpUpdateAlertType = new UpdateAlertType();
          tmpUpdateAlertType.setID(getResultSetInteger(rs, "ID"));
          tmpUpdateAlertType.setUpdateAlertID(getResultSetInteger(rs, "UPDATE_ALERT_ID"));
          tmpUpdateAlertType.setActionType(getResultSetString(rs, "ACTION_TYPE"));
          tmpUpdateAlertType.setNeedReply(getResultSetString(rs, "NEED_REPLY"));
          tmpUpdateAlertType.setNotifyWay(getResultSetString(rs, "NOTIFY_WAY"));
          tmpUpdateAlertType.setRecurEvent(getResultSetString(rs, "RECUR_EVENT"));
          tmpUpdateAlertType.setAlertTimeType(getResultSetString(rs, "ALERT_TIME_TYPE"));
          tmpUpdateAlertType.setAlertTime(getResultSetInteger(rs, "ALERT_TIME"));
          tmpUpdateAlertType.setDueDate(getResultSetTimestamp(rs, "DUE_DATE"));
          tmpUpdateAlertType.setMessage(getResultSetString(rs, "MESSAGE"));
          tmpUpdateAlertType.setStatus(getResultSetString(rs, "STATUS"));
          tmpUpdateAlertType.setAlertSubject(getResultSetString(rs, "ALERT_SUBJECT"));
          tmpUpdateAlertType.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpUpdateAlertType.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpUpdateAlertType.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpUpdateAlertType.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpUpdateAlertType.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpUpdateAlertType.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpUpdateAlertType.setCreatorName(UserInfoFactory.getUserFullName(tmpUpdateAlertType
              .getCreatorID()));
          tmpUpdateAlertType.setUpdaterName(UserInfoFactory.getUserFullName(tmpUpdateAlertType
              .getUpdaterID()));
          resultList.add(tmpUpdateAlertType);
        }
      }
      catch (ApplicationException appEx) {
        throw appEx;
      }
      catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      }
      catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      }
      finally {
        try {
          rs.close();
        }
        catch (Exception ignore) {
        }
        finally {
          rs = null;
        }
        try {
          preStat.close();
        }
        catch (Exception ignore) {
        }
        finally {
          preStat = null;
        }
      }
    }

    return resultList;
}
  public synchronized String[] getCreatorIDByUpdateAlertIDByOwnerID(Integer updateAlertID, String actionType, Integer curUserID) throws
        ApplicationException {
      PreparedStatement preStat = null;
      ResultSet rs = null;
      StringBuffer sqlStat = new StringBuffer();
      List resultList = new ArrayList();

      synchronized (dbConn) {
        try {
          sqlStat.append("SELECT DISTINCT(A.ID), A.UPDATE_ALERT_ID, A.ACTION_TYPE, A.NEED_REPLY, A.NOTIFY_WAY, A.RECUR_EVENT, A.ALERT_TIME_TYPE, A.ALERT_TIME, A.DUE_DATE, A.MESSAGE, A.STATUS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
          sqlStat.append("FROM   UPDATE_ALERT_TYPE A ");
          sqlStat.append("WHERE  (A.UPDATE_ALERT_ID = ?) AND (A.RECORD_STATUS=?) ");
          if (curUserID!=null){
            sqlStat.append("AND  A.CREATOR_ID = ? ");
          }
          if ( (actionType != null) && (! ("ALL".equals(actionType))))
            sqlStat.append("AND  (A.ACTION_TYPE = ?) ");
          else if (actionType == null)
            sqlStat.append("AND  (A.ACTION_TYPE <> 'I') ");
          preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
          int i=0;
          this.setPrepareStatement(preStat, ++i, updateAlertID);
          this.setPrepareStatement(preStat, ++i, GlobalConstant.STATUS_ACTIVE);
          if (curUserID!=null){
            this.setPrepareStatement(preStat, ++i, curUserID);
          }
          if ( (actionType != null) && (! ("ALL".equals(actionType))))
            this.setPrepareStatement(preStat, ++i, actionType);
          rs = preStat.executeQuery();
          while (rs.next()) {
/*            UpdateAlertType tmpUpdateAlertType = new UpdateAlertType();
            tmpUpdateAlertType.setID(getResultSetInteger(rs, "ID"));
            tmpUpdateAlertType.setUpdateAlertID(getResultSetInteger(rs, "UPDATE_ALERT_ID"));
            tmpUpdateAlertType.setActionType(getResultSetString(rs, "ACTION_TYPE"));
            tmpUpdateAlertType.setNeedReply(getResultSetString(rs, "NEED_REPLY"));
            tmpUpdateAlertType.setNotifyWay(getResultSetString(rs, "NOTIFY_WAY"));
            tmpUpdateAlertType.setRecurEvent(getResultSetString(rs, "RECUR_EVENT"));
            tmpUpdateAlertType.setAlertTimeType(getResultSetString(rs, "ALERT_TIME_TYPE"));
            tmpUpdateAlertType.setAlertTime(getResultSetInteger(rs, "ALERT_TIME"));
            tmpUpdateAlertType.setDueDate(getResultSetTimestamp(rs, "DUE_DATE"));
            tmpUpdateAlertType.setMessage(getResultSetString(rs, "MESSAGE"));
            tmpUpdateAlertType.setStatus(getResultSetString(rs, "STATUS"));
            tmpUpdateAlertType.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
            tmpUpdateAlertType.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));*/
            Integer creatorID = getResultSetInteger(rs, "CREATOR_ID");
/*            tmpUpdateAlertType.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
            tmpUpdateAlertType.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
            tmpUpdateAlertType.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
            tmpUpdateAlertType.setCreatorName(UserInfoFactory.getUserFullName(tmpUpdateAlertType.getCreatorID()));
            tmpUpdateAlertType.setUpdaterName(UserInfoFactory.getUserFullName(tmpUpdateAlertType.getUpdaterID()));*/
            resultList.add(TextUtility.formatIntegerObj(creatorID));
          }
        }
        catch (ApplicationException appEx) {
          throw appEx;
        }
        catch (SQLException sqle) {
          log.error(sqle, sqle);
          throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
        }
        catch (Exception e) {
          log.error(e, e);
          throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
        } finally {
          try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
          try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
        }
      }
      return Utility.getStringArray(resultList);
    }

  public synchronized AbstractBaseObject getIDByTypeUpdateAlertID(String eventType, Integer updateAlertID) throws ApplicationException {

    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    UpdateAlertType tmpUpdateAlertType = null;

    synchronized (dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.UPDATE_ALERT_ID, A.ACTION_TYPE, A.NEED_REPLY, A.NOTIFY_WAY, A.RECUR_EVENT, A.ALERT_TIME_TYPE, A.ALERT_TIME, A.DUE_DATE, A.MESSAGE, A.STATUS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   UPDATE_ALERT_TYPE A ");
        sqlStat.append("WHERE  A.UPDATE_ALERT_ID = ? AND A.ACTION_TYPE = ? AND A.RECORD_STATUS = ?  ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, updateAlertID);
        this.setPrepareStatement(preStat, 2, eventType);
        this.setPrepareStatement(preStat, 3, GlobalConstant.STATUS_ACTIVE);
        rs = preStat.executeQuery();
        if (rs.next()) {
          tmpUpdateAlertType =  new UpdateAlertType();
          tmpUpdateAlertType.setID(getResultSetInteger(rs, "ID"));
          tmpUpdateAlertType.setUpdateAlertID(getResultSetInteger(rs, "UPDATE_ALERT_ID"));
          tmpUpdateAlertType.setActionType(getResultSetString(rs, "ACTION_TYPE"));
          tmpUpdateAlertType.setNeedReply(getResultSetString(rs, "NEED_REPLY"));
          tmpUpdateAlertType.setNotifyWay(getResultSetString(rs, "NOTIFY_WAY"));
          tmpUpdateAlertType.setRecurEvent(getResultSetString(rs, "RECUR_EVENT"));
          tmpUpdateAlertType.setAlertTimeType(getResultSetString(rs, "ALERT_TIME_TYPE"));
          tmpUpdateAlertType.setAlertTime(getResultSetInteger(rs, "ALERT_TIME"));
          tmpUpdateAlertType.setDueDate(getResultSetTimestamp(rs, "DUE_DATE"));
          tmpUpdateAlertType.setMessage(getResultSetString(rs, "MESSAGE"));
          tmpUpdateAlertType.setStatus(getResultSetString(rs, "STATUS"));
          tmpUpdateAlertType.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpUpdateAlertType.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpUpdateAlertType.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpUpdateAlertType.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpUpdateAlertType.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpUpdateAlertType.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpUpdateAlertType.setCreatorName(UserInfoFactory.getUserFullName(tmpUpdateAlertType.getCreatorID()));
          tmpUpdateAlertType.setUpdaterName(UserInfoFactory.getUserFullName(tmpUpdateAlertType.getUpdaterID()));
        }
      }
      catch (ApplicationException appEx) {
        throw appEx;
      }
      catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      }
      catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      }
      finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
    return tmpUpdateAlertType;
  }

  public synchronized void updateStatusByID(Integer objID, String status) throws ApplicationException {
  PreparedStatement preStat = null;
  StringBuffer sqlStat = new StringBuffer();

  synchronized(dbConn) {
    try {
      int updateCnt = 0;
      sqlStat.append("UPDATE UPDATE_ALERT_TYPE ");
      sqlStat.append("SET  RECORD_STATUS=? ");
      sqlStat.append("WHERE  ID=? ");
      preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
      setPrepareStatement(preStat, 1, status);
      setPrepareStatement(preStat, 2, objID);
      updateCnt = preStat.executeUpdate();
    } catch (SQLException sqle) {
      log.error(sqle, sqle);
      throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
    } catch (Exception e) {
      log.error(e, e);
      throw new ApplicationException(ErrorConstant.DB_DELETE_ERROR, e);
    } finally {
      try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
    }
  }
 }

  public synchronized void updateDueDateByID(Integer objID, String duedate) throws ApplicationException {
  PreparedStatement preStat = null;
  StringBuffer sqlStat = new StringBuffer();
  Timestamp date = TextUtility.parseDBDateTimeToTimeStamp(duedate);
  
  synchronized(dbConn) {
    try {
      sqlStat.append("UPDATE UPDATE_ALERT_TYPE ");
      sqlStat.append("SET  DUE_DATE=? ");
      sqlStat.append("WHERE  ID=? ");
      preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
      setPrepareStatement(preStat, 1, date);
      setPrepareStatement(preStat, 2, objID);
      preStat.executeUpdate();
    } catch (SQLException sqle) {
      log.error(sqle, sqle);
      throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
    } catch (Exception e) {
      log.error(e, e);
      throw new ApplicationException(ErrorConstant.DB_DELETE_ERROR, e);
    } finally {
      try { preStat.close(); dbConn.commit();} catch (Exception ignore) {} finally { preStat = null; }
    }
  }
 }

  public synchronized void updateInvitationCancelStatusByID(Integer objID) throws ApplicationException {
  PreparedStatement preStat = null;
  StringBuffer sqlStat = new StringBuffer();

  synchronized(dbConn) {
    try {
      sqlStat.append("UPDATE UPDATE_ALERT_TYPE ");
      sqlStat.append("SET  STATUS=? ");
      sqlStat.append("WHERE  ID=? ");
      preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
      setPrepareStatement(preStat, 1, UpdateAlert.STATUS_CANCEL);
      setPrepareStatement(preStat, 2, objID);
      preStat.executeUpdate();
    } catch (SQLException sqle) {
      log.error(sqle, sqle);
      throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
    } catch (Exception e) {
      log.error(e, e);
      throw new ApplicationException(ErrorConstant.DB_DELETE_ERROR, e);
    } finally {
      try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
    }
  }
 }
 public synchronized void hardDeleteByID(Integer id) throws ApplicationException {
   PreparedStatement preStat = null;
   StringBuffer sqlStat = new StringBuffer();
   
   //UpdateAlertType tmpUpdateAlertType = (UpdateAlertType)((UpdateAlertType)obj).clone();

   synchronized(dbConn) {
     try {
       int updateCnt = 0;
       sqlStat.append("DELETE ");
       sqlStat.append("FROM   UPDATE_ALERT_TYPE ");
       sqlStat.append("WHERE  ID=?  ");
       preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
       setPrepareStatement(preStat, 1,id);
       updateCnt = preStat.executeUpdate();
     } catch (SQLException sqle) {
       log.error(sqle, sqle);
       throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
     } catch (Exception e) {
       log.error(e, e);
       throw new ApplicationException(ErrorConstant.DB_DELETE_ERROR, e);
     } finally {
       try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
     }
   }
 }
 public  AbstractBaseObject getByupdateAlertTypeID(Integer id) throws ApplicationException {
    return getByupdateAlertTypeID(id,GlobalConstant.RECORD_STATUS_ACTIVE);
  }
/**
 * @param id
 * @return
 * @throws ApplicationException
 */
public AbstractBaseObject getByupdateAlertTypeID(Integer id,String status) throws ApplicationException {
  PreparedStatement preStat = null;
  ResultSet rs = null;
  StringBuffer sqlStat = new StringBuffer();
  synchronized(dbConn) {
    try {
      sqlStat.append("SELECT A.ID, A.UPDATE_ALERT_ID, A.ACTION_TYPE, A.NEED_REPLY, A.NOTIFY_WAY, A.RECUR_EVENT, A.ALERT_TIME_TYPE, A.ALERT_TIME, A.DUE_DATE, A.MESSAGE, A.STATUS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
      sqlStat.append("FROM   UPDATE_ALERT_TYPE A ");
      sqlStat.append("WHERE  A.ID = ? ");
      if(!Utility.isEmpty(status)){
        sqlStat.append(" AND A.RECORD_STATUS = ? ");
      }
      preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
      this.setPrepareStatement(preStat, 1, id);
      if(!Utility.isEmpty(status)){
        this.setPrepareStatement(preStat, 2, status);
      }
      rs = preStat.executeQuery();
      if (rs.next()) {
        UpdateAlertType tmpUpdateAlertType = new UpdateAlertType();
        tmpUpdateAlertType.setID(getResultSetInteger(rs, "ID"));
        tmpUpdateAlertType.setUpdateAlertID(getResultSetInteger(rs, "UPDATE_ALERT_ID"));
        tmpUpdateAlertType.setActionType(getResultSetString(rs, "ACTION_TYPE"));
        tmpUpdateAlertType.setNeedReply(getResultSetString(rs, "NEED_REPLY"));
        tmpUpdateAlertType.setNotifyWay(getResultSetString(rs, "NOTIFY_WAY"));
        tmpUpdateAlertType.setRecurEvent(getResultSetString(rs, "RECUR_EVENT"));
        tmpUpdateAlertType.setAlertTimeType(getResultSetString(rs, "ALERT_TIME_TYPE"));
        tmpUpdateAlertType.setAlertTime(getResultSetInteger(rs, "ALERT_TIME"));
        tmpUpdateAlertType.setDueDate(getResultSetTimestamp(rs, "DUE_DATE"));
        tmpUpdateAlertType.setMessage(getResultSetString(rs, "MESSAGE"));
        tmpUpdateAlertType.setStatus(getResultSetString(rs, "STATUS"));
        tmpUpdateAlertType.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
        tmpUpdateAlertType.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
        tmpUpdateAlertType.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
        tmpUpdateAlertType.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
        tmpUpdateAlertType.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));

        tmpUpdateAlertType.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
        tmpUpdateAlertType.setCreatorName(UserInfoFactory.getUserFullName(tmpUpdateAlertType.getCreatorID()));
        tmpUpdateAlertType.setUpdaterName(UserInfoFactory.getUserFullName(tmpUpdateAlertType.getUpdaterID()));
        return(tmpUpdateAlertType);
      } else {
        throw new ApplicationException(ErrorConstant.DB_RECORD_NOT_FOUND_ERROR);
      }
    } catch (ApplicationException appEx) {
      throw appEx;
    } catch (SQLException sqle) {
      log.error(sqle, sqle);
      throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
    } catch (Exception e) {
      log.error(e, e);
      throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
    } finally {
      try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
      try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
    }
  }
}
 //king---add---start
 public  AbstractBaseObject getByupdateAlertID(Integer id) throws ApplicationException {
	    PreparedStatement preStat = null;
	    ResultSet rs = null;
	    StringBuffer sqlStat = new StringBuffer();
	    synchronized(dbConn) {
	      try {
	        sqlStat.append("SELECT A.ID, A.UPDATE_ALERT_ID, A.ACTION_TYPE, A.NEED_REPLY, A.NOTIFY_WAY, A.RECUR_EVENT, A.ALERT_TIME_TYPE, A.ALERT_TIME, A.DUE_DATE, A.MESSAGE, A.STATUS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
	        sqlStat.append("FROM   UPDATE_ALERT_TYPE A ");
	        sqlStat.append("WHERE  A.update_alert_id = ? AND A.RECORD_STATUS = ? ");
	        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
	        this.setPrepareStatement(preStat, 1, id);
	        this.setPrepareStatement(preStat, 2, GlobalConstant.RECORD_STATUS_ACTIVE);
	        rs = preStat.executeQuery();
	        if (rs.next()) {
	          UpdateAlertType tmpUpdateAlertType = new UpdateAlertType();
	          tmpUpdateAlertType.setID(getResultSetInteger(rs, "ID"));
	          tmpUpdateAlertType.setUpdateAlertID(getResultSetInteger(rs, "UPDATE_ALERT_ID"));
	          tmpUpdateAlertType.setActionType(getResultSetString(rs, "ACTION_TYPE"));
	          tmpUpdateAlertType.setNeedReply(getResultSetString(rs, "NEED_REPLY"));
	          tmpUpdateAlertType.setNotifyWay(getResultSetString(rs, "NOTIFY_WAY"));
	          tmpUpdateAlertType.setRecurEvent(getResultSetString(rs, "RECUR_EVENT"));
	          tmpUpdateAlertType.setAlertTimeType(getResultSetString(rs, "ALERT_TIME_TYPE"));
	          tmpUpdateAlertType.setAlertTime(getResultSetInteger(rs, "ALERT_TIME"));
	          tmpUpdateAlertType.setDueDate(getResultSetTimestamp(rs, "DUE_DATE"));
	          tmpUpdateAlertType.setMessage(getResultSetString(rs, "MESSAGE"));
	          tmpUpdateAlertType.setStatus(getResultSetString(rs, "STATUS"));
	          tmpUpdateAlertType.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
	          tmpUpdateAlertType.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
	          tmpUpdateAlertType.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
	          tmpUpdateAlertType.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
	          tmpUpdateAlertType.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));

	          tmpUpdateAlertType.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
	          tmpUpdateAlertType.setCreatorName(UserInfoFactory.getUserFullName(tmpUpdateAlertType.getCreatorID()));
	          tmpUpdateAlertType.setUpdaterName(UserInfoFactory.getUserFullName(tmpUpdateAlertType.getUpdaterID()));
	          return(tmpUpdateAlertType);
	        } else {
	          throw new ApplicationException(ErrorConstant.DB_RECORD_NOT_FOUND_ERROR);
	        }
	      } catch (ApplicationException appEx) {
	        throw appEx;
	      } catch (SQLException sqle) {
	        log.error(sqle, sqle);
	        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
	      } catch (Exception e) {
	        log.error(e, e);
	        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
	      } finally {
	        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
	        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
	      }
	    }
	  }
//king---add---end
 public  AbstractBaseObject getIDByUpdateAlertIDAndActionType(Integer updateAlertID,String actionType) throws ApplicationException {
	    PreparedStatement preStat = null;
	    ResultSet rs = null;
	    StringBuffer sqlStat = new StringBuffer();
	    synchronized(dbConn) {
	      try {
	        sqlStat.append("SELECT A.ID, A.UPDATE_ALERT_ID, A.ACTION_TYPE, A.NEED_REPLY, A.NOTIFY_WAY, A.RECUR_EVENT, A.ALERT_TIME_TYPE, A.ALERT_TIME, A.DUE_DATE, A.MESSAGE, A.STATUS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
	        sqlStat.append("FROM   UPDATE_ALERT_TYPE A ");
	        sqlStat.append("WHERE  A.UPDATE_ALERT_ID = ? AND A.ACTION_TYPE = ? AND A.RECORD_STATUS = ? ");
	        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
	        this.setPrepareStatement(preStat, 1, updateAlertID);
	        this.setPrepareStatement(preStat, 2, actionType);
	        this.setPrepareStatement(preStat, 3, GlobalConstant.RECORD_STATUS_ACTIVE);
	        rs = preStat.executeQuery();
	        if (rs.next()) {
	          UpdateAlertType tmpUpdateAlertType = new UpdateAlertType();
	          tmpUpdateAlertType.setID(getResultSetInteger(rs, "ID"));
	          tmpUpdateAlertType.setUpdateAlertID(getResultSetInteger(rs, "UPDATE_ALERT_ID"));
	          tmpUpdateAlertType.setActionType(getResultSetString(rs, "ACTION_TYPE"));
	          tmpUpdateAlertType.setNeedReply(getResultSetString(rs, "NEED_REPLY"));
	          tmpUpdateAlertType.setNotifyWay(getResultSetString(rs, "NOTIFY_WAY"));
	          tmpUpdateAlertType.setRecurEvent(getResultSetString(rs, "RECUR_EVENT"));
	          tmpUpdateAlertType.setAlertTimeType(getResultSetString(rs, "ALERT_TIME_TYPE"));
	          tmpUpdateAlertType.setAlertTime(getResultSetInteger(rs, "ALERT_TIME"));
	          tmpUpdateAlertType.setDueDate(getResultSetTimestamp(rs, "DUE_DATE"));
	          tmpUpdateAlertType.setMessage(getResultSetString(rs, "MESSAGE"));
	          tmpUpdateAlertType.setStatus(getResultSetString(rs, "STATUS"));
	          tmpUpdateAlertType.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
	          tmpUpdateAlertType.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
	          tmpUpdateAlertType.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
	          tmpUpdateAlertType.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
	          tmpUpdateAlertType.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));

	          tmpUpdateAlertType.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
	          tmpUpdateAlertType.setCreatorName(UserInfoFactory.getUserFullName(tmpUpdateAlertType.getCreatorID()));
	          tmpUpdateAlertType.setUpdaterName(UserInfoFactory.getUserFullName(tmpUpdateAlertType.getUpdaterID()));
	          return(tmpUpdateAlertType);
	        } else {
	          throw new ApplicationException(ErrorConstant.DB_RECORD_NOT_FOUND_ERROR);
	        }
	      } catch (ApplicationException appEx) {
	        throw appEx;
	      } catch (SQLException sqle) {
	        log.error(sqle, sqle);
	        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
	      } catch (Exception e) {
	        log.error(e, e);
	        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
	      } finally {
	        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
	        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
	      }
	    }
	  }

 public  UpdateAlertType getByUpdateAlertIDAndActionType(
     Integer updateAlertID,
     String actionType) throws ApplicationException {
   PreparedStatement preStat = null;
   ResultSet rs = null;
   StringBuffer sqlStat = new StringBuffer();
   synchronized (dbConn) {
     try {
       sqlStat.append("SELECT A.ID, A.UPDATE_ALERT_ID, A.ACTION_TYPE, A.NEED_REPLY, A.NOTIFY_WAY, A.RECUR_EVENT, A.ALERT_TIME_TYPE, A.ALERT_TIME, A.DUE_DATE, A.MESSAGE, A.STATUS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
       sqlStat.append("FROM UPDATE_ALERT_TYPE A ");
       sqlStat.append("WHERE  A.UPDATE_ALERT_ID = ? AND A.ACTION_TYPE = ? ");
       preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
       this.setPrepareStatement(preStat, 1, updateAlertID);
       this.setPrepareStatement(preStat, 2, actionType);
       rs = preStat.executeQuery();
       if (rs.next()) {
         UpdateAlertType tmpUpdateAlertType = new UpdateAlertType();
         tmpUpdateAlertType.setID(getResultSetInteger(rs, "ID"));
         tmpUpdateAlertType.setUpdateAlertID(getResultSetInteger(rs, "UPDATE_ALERT_ID"));
         tmpUpdateAlertType.setActionType(getResultSetString(rs, "ACTION_TYPE"));
         tmpUpdateAlertType.setNeedReply(getResultSetString(rs, "NEED_REPLY"));
         tmpUpdateAlertType.setNotifyWay(getResultSetString(rs, "NOTIFY_WAY"));
         tmpUpdateAlertType.setRecurEvent(getResultSetString(rs, "RECUR_EVENT"));
         tmpUpdateAlertType.setAlertTimeType(getResultSetString(rs, "ALERT_TIME_TYPE"));
         tmpUpdateAlertType.setAlertTime(getResultSetInteger(rs, "ALERT_TIME"));
         tmpUpdateAlertType.setDueDate(getResultSetTimestamp(rs, "DUE_DATE"));
         tmpUpdateAlertType.setMessage(getResultSetString(rs, "MESSAGE"));
         tmpUpdateAlertType.setStatus(getResultSetString(rs, "STATUS"));
         tmpUpdateAlertType.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
         tmpUpdateAlertType.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
         tmpUpdateAlertType.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
         tmpUpdateAlertType.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
         tmpUpdateAlertType.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));

         tmpUpdateAlertType.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
         tmpUpdateAlertType.setCreatorName(UserInfoFactory.getUserFullName(tmpUpdateAlertType.getCreatorID()));
         tmpUpdateAlertType.setUpdaterName(UserInfoFactory.getUserFullName(tmpUpdateAlertType.getUpdaterID()));
         return (tmpUpdateAlertType);
       } else {
         throw new ApplicationException(ErrorConstant.DB_RECORD_NOT_FOUND_ERROR);
       }
     } catch (ApplicationException appEx) {
       throw appEx;
     } catch (SQLException sqle) {
       log.error(sqle, sqle);
       throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
     } catch (Exception e) {
       log.error(e, e);
       throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
     } finally {
       try {
         rs.close();
       } catch (Exception ignore) {
       } finally {
         rs = null;
       }
       try {
         preStat.close();
       } catch (Exception ignore) {
       } finally {
         preStat = null;
       }
     }
   }
 }

  public List getActiveUpdateAlertType(Integer updateAlertID,String actionType ) throws ApplicationException {
    List result = new ArrayList();
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    synchronized (dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.UPDATE_ALERT_ID, A.ACTION_TYPE, A.NEED_REPLY, A.NOTIFY_WAY, A.RECUR_EVENT, A.ALERT_TIME_TYPE, A.ALERT_TIME, A.DUE_DATE, A.MESSAGE, A.STATUS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM UPDATE_ALERT_TYPE A ");
        sqlStat.append("WHERE  A.UPDATE_ALERT_ID = ? AND A.ACTION_TYPE = ? AND A.STATUS IS NULL AND ( A.DUE_DATE IS NULL OR A.DUE_DATE > ?)");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        setPrepareStatement(preStat, 1, updateAlertID);
        setPrepareStatement(preStat, 2, actionType);
        Timestamp currTime = Utility.getCurrentTimestamp();
        Timestamp oneDayBeforeCurrTime = Utility.addDay(currTime, -1);
        setPrepareStatement(preStat, 3, oneDayBeforeCurrTime);
        rs = preStat.executeQuery();
        while(rs.next()) {
          UpdateAlertType alertType = new UpdateAlertType();
          alertType.setID(getResultSetInteger(rs, "ID"));
          alertType.setUpdateAlertID(getResultSetInteger(rs, "UPDATE_ALERT_ID"));
          alertType.setActionType(getResultSetString(rs, "ACTION_TYPE"));
          alertType.setNeedReply(getResultSetString(rs, "NEED_REPLY"));
          alertType.setNotifyWay(getResultSetString(rs, "NOTIFY_WAY"));
          alertType.setRecurEvent(getResultSetString(rs, "RECUR_EVENT"));
          alertType.setAlertTimeType(getResultSetString(rs, "ALERT_TIME_TYPE"));
          alertType.setAlertTime(getResultSetInteger(rs, "ALERT_TIME"));
          alertType.setDueDate(getResultSetTimestamp(rs, "DUE_DATE"));
          alertType.setMessage(getResultSetString(rs, "MESSAGE"));
          alertType.setStatus(getResultSetString(rs, "STATUS"));
          alertType.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          alertType.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          alertType.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          alertType.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          alertType.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
		  alertType.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          alertType.setCreatorName(UserInfoFactory.getUserFullName(alertType.getCreatorID()));
          alertType.setUpdaterName(UserInfoFactory.getUserFullName(alertType.getUpdaterID()));
          result.add(alertType);
        }
      }catch( Exception e ) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        DbUtils.closeQuietly(rs);
        DbUtils.closeQuietly(preStat);
      }
    }
    return result;
  }
}
